from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage


class LoginPage(BasePage):
    url = r'/bsams/front/login.do'
    # 登录定位
    taksid_loc = (By.ID, 'taskId')
    username_loc = (By.ID, 'loginName')
    password_loc = (By.ID, 'password')
    vericode_loc = (By.ID, 'vericode')
    login_btn_loc = (By.XPATH, '//*[@id="fmedit"]/div[2]/div[6]/input')

    # def __init__(self, driver):
    #     super().__init__(driver)
    #     self.get_url(self.url)

    def login(self, taskid=1, username='student', password='123456', vericode='shtd'):
        self.open()
        self.input_ele(self.taksid_loc, taskid)
        self.input_ele(self.username_loc, username)
        self.input_ele(self.password_loc, password)
        self.input_ele(self.vericode_loc, vericode)
        self.ele_click(self.login_btn_loc)
        sleep(3)

    def logout(self):
        pass


if __name__ == '__main__':
    taskid = 1
    username = 'student'
    password = '123456'
    vericode = 'shtd'

    chrome_location = r'D:\RJCS\谷歌浏览器内网通紫域和驱动安装\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)

    login = LoginPage(driver)
    login.login(taskid, username, password, vericode)

    driver.quit()
